package DTO;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Row {
	private Map<String, Object> _Fileds;
	
	private boolean _Deleted;
	public Map<String, Object> get_Fileds() {		
		return _Fileds;
	}
 
	public void set_Fileds(Map<String, Object> _Fileds) {
		if(_Fileds == null)
			this._Fileds = new Hashtable<String, Object>();
		else
			this._Fileds = _Fileds;
	} 
	
	public void add_Fields(Map<String, Object> _Fileds) {
		this._Fileds.putAll(_Fileds);
	}
	
	public Row(Map<String, Object> fields, boolean isDel)
	{
		this.set_Fileds(fields);
		this.set_Deleted(isDel);
		Set s = this.get_Fileds().entrySet();
		
	}
	
	public Row(Field[] fields, Object[] values, boolean isDel)
	{
		
	}
	
	
	public boolean Compare(Row row)
	{
		boolean res = false;
		if(row == null) return res;
		Map<String,Object> map = row.get_Fileds();
		Set s = map.entrySet();
		Set set = this.get_Fileds().entrySet();
		
		Iterator it = s.iterator();
		Iterator iterator ;
		int d = 0, d2 = 0, d3 = 0;
		while(it.hasNext())
		{
			Map.Entry mRow = (Map.Entry)it.next();
			String f1 = String.valueOf(mRow.getKey());
			
			Object val1 = mRow.getValue();
			
			iterator = set.iterator();
			while(iterator.hasNext())
			{
				Map.Entry m = (Map.Entry)iterator.next();
				String f2 = String.valueOf(m.getKey());
				Object val2 = m.getValue();		
				if(f1.equals(f2) && (String.valueOf(val1)).equals(String.valueOf(val2))
						&& !f2.equals("Deleted"))
					d++;	
			}
			if(!f1.equals("Deleted"))
				d2++;
		}
		if(d == d2 ) 
			res = true;
		
		return res;
	}
	

	public boolean is_Deleted() {
		return _Deleted;
	}

	public void set_Deleted(boolean _Deleted) {
		this._Deleted = _Deleted;
	}
	
	public Row clone()
	{
		Row row = new Row(this.get_Fileds(), _Deleted);
		return row;
	}
	
}
